package com.lin.filegraph.utils.componentRule;

import com.lin.filegraph.utils.cluster.NeighbourRank;
import com.lin.filegraph.utils.compdg.ComponentGraph;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 16:06
 */

public class ComponentRules {

    public static void executeRulePre(ComponentGraph graph) {
        //继承
        System.out.println("继承or定义or组合...");
        DetectLogic.unionInherOrCombin(graph);

        // 组件化规则1 (紧耦合)
        NeighbourRank.neighbourUnion(graph);
        System.out.println("组件化规则——紧耦合...");
        DetectCouples.removeCouples(graph);

        // 组件化规则2 (域实体集)
//		System.out.println("域...");
//		Region.executeReg(graph.getAllComponents().size(), graph);

        //组件化规则3 (单独依赖)
        NeighbourRank.neighbourUnion(graph);
        System.out.println("组件化规则——单独依赖...");
        SingleDepend.unionSD(graph);

        //组件规则4 (闭环依赖)
        NeighbourRank.neighbourUnion(graph);
        System.out.println("组件化规则——闭环依赖...");
        CircleRules rules = new CircleRules(graph);
        rules.removeLoopIgnoreRegion();
    }

    public static void executeRule(ComponentGraph graph) {
        int numPre=graph.getAllComponents().size();

        // 组件化规则5 (开环依赖)
        System.out.println("组件化规则——开环依赖...");
        DetectTransDepend.removeOL(graph);
//		new DetectOpenLoop(graph).executeOLoop();

        System.out.println("组件化规则——紧耦合...");
        DetectCouples.removeCouples(graph);

        //组件化规则3 (单独依赖)
        System.out.println("组件化规则——单独依赖...");
        SingleDepend.unionSD(graph);

        //组件规则4 (闭环依赖)
        System.out.println("组件化规则——闭环依赖...");
        CircleRules rules = new CircleRules(graph);
//		rules.removeLoop();
        rules.removeLoopIgnoreRegion();

        if(graph.getAllComponents().size()!=numPre){
            executeRule(graph);
        }
    }

    public static void executeRule2(ComponentGraph graph) {
        int numPre=graph.getAllComponents().size();

        // 组件化规则1 (紧耦合)
        System.out.println("组件化规则——紧耦合...");
//		double comSize = num * Threshold.comScale;
        DetectCouples.removeCouples(graph);
        //组件规则4 (闭环依赖)
        System.out.println("组件化规则——闭环依赖...");
        CircleRules rules = new CircleRules(graph);
        rules.removeLoopIgnoreRegion();
//		System.out.println("组件化规则——紧耦合...");
//		DetectCouples.removeCouples(graph);

        if(graph.getAllComponents().size()!=numPre){
            executeRule2(graph);
        }
    }

}

